#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

//0 1 1 2 3 5 8 13  21
int main()
{
	int a = 0; int b = 1,c=0;
	int n = 0; int i = 0;
	scanf("%d", &n);
	for (i = 0;c<=n; i++)
	{
		c = a + b;
		a = b;
		b = c;
	}
	int num1 = b - n;
	int num2= n - a;
	if (num1 < num2)
	{
		printf("%d\n",num1 );
	}
	else
	{
		printf("%d\n", num2);
	}
	
	return 0;
}